package battlenetwork;

import java.util.Observable;
import java.util.Observer;

public class Tile extends Observable implements Observer{

	private Unit onTile;
	private boolean friendly;
	public Tile(){
		this.onTile = null;
		this.friendly = false;
	}
	
	public void setUnit(Unit unit){
		onTile = unit;
		unit.addObserver(this);
	}

	public boolean isFree() {
		return (onTile == null);
	}
	public boolean isFriendly(){
		return friendly;
	}
	
	public void setFriendly(boolean b){
		this.friendly = b;
	}

	public void damage(int damage) {
		if(onTile != null){
			onTile.damage(damage);
		}
		
	}

	@Override
	public void update(Observable o, Object arg) {
		onTile = null;
		setChanged();
		notifyObservers();
		
	}
	
}
